import { reactive } from "vue";
import type { FormRules } from "element-plus";
import { isPhone, isEmail } from "@pureadmin/utils";
/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  name: [{ required: true, message: "客户名称为必填项", trigger: "blur" }],
  code: [{ required: true, message: "客户编码必填项", trigger: "blur" }],
  phone: [
  	{ required: true, message: "电话为必填项", trigger: "blur" },
  	{
  		validator: (rule, value, callback) => {
  			if (value === "") {
  				callback();
  			} else if (!isPhone(value)) {
  				callback(new Error("请输入正确的手机号码格式"));
  			} else {
  				callback();
  			}
  		},
  		trigger: "blur"
  	}
  ],
  email: [
  	{ required: true, message: "邮箱为必填项", trigger: "blur" },
  	{
  		validator: (rule, value, callback) => {
  			if (value === "") {
  				callback();
  			} else if (!isEmail(value)) {
  				callback(new Error("请输入正确的邮箱格式"));
  			} else {
  				callback();
  			}
  		},
  		trigger: "blur"
  	}
  ]
});
